package com.applicationLayer.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.applicationLayer.formbean.CovoitureurForm;
import com.applicationLayer.formbean.ListPathForm;
import com.applicationLayer.formbean.SearchingPathForm;
import com.applicationLayer.sessionbean.SessionBean;
import com.common.domainService.IPathService;
import com.opensymphony.xwork2.ActionSupport;

public class HomeAction extends ActionSupport{

	private static final long serialVersionUID = 7183575015520908217L;
	Logger logger = Logger.getLogger(HomeAction.class);
	
	//form bean declaration
	private SearchingPathForm searchingPathForm;
	
	private ArrayList<ListPathForm> pathList;
	private List<ListPathForm> pathRegisteredList;
	private List<ListPathForm> pathPostedList;
	
	//services
	private IPathService pathService;
	
	public String initHome(){
		pathList = new ArrayList<ListPathForm>();
		if(!SessionBean.checkUserInSession()){
			pathList = (ArrayList<ListPathForm>) pathService.getLastPath();
			return "SUCCESS";
		}
		SessionBean.UnsetFromSession("pathDetails");
		SessionBean.UnsetFromSession("covoitureurDetails");
		CovoitureurForm co = (CovoitureurForm) SessionBean.getFromSession("loggedUser");
		pathList = (ArrayList<ListPathForm>) pathService.getDefaultPath(co.getNum_ville());
		pathRegisteredList = pathService.getPathForCovoitureurById(co.getId_covoitureur(),false);
		pathPostedList = pathService.getPathPostedByCovoitureurId(co.getId_covoitureur());
		return "SUCCESS";
	}
	
	/**
	 * Method used for preparing a path
	 * @return
	 */
	public String pathResearsh(){
		System.out.println("Preparer un trajet");
		System.out.println(searchingPathForm.getDeparture());
		System.out.println(searchingPathForm.getArrival());
		System.out.println(searchingPathForm.getDate());
		
		
		return "SUCCESS";
	}
	
	/**
	 * Method used for posting a path
	 * @return
	 */
	public String pathPost(){
		return "SUCCESS";
	}
	
	/** GETTER **/
	
	public ArrayList<ListPathForm> getPathList() {
		return pathList;
	}
	
	public SearchingPathForm getSearchingPathForm() {
		return searchingPathForm;
	}

	public IPathService getPathService() {
		return pathService;
	}
	
	/** SETTER **/
	

	public void setSearchingPathForm(SearchingPathForm searshingPathForm) {
		this.searchingPathForm = searshingPathForm;
	}
	
	public void setPathService(IPathService pathService) {
		this.pathService = pathService;
	}
	
	public void setPathList(ArrayList<ListPathForm> pathList) {
		this.pathList = pathList;
	}

	public List<ListPathForm> getPathRegisteredList() {
		return pathRegisteredList;
	}

	public void setPathRegisteredList(List<ListPathForm> pathRegisteredList) {
		this.pathRegisteredList = pathRegisteredList;
	}

	public List<ListPathForm> getPathPostedList() {
		return pathPostedList;
	}

	public void setPathPostedList(List<ListPathForm> pathPostedList) {
		this.pathPostedList = pathPostedList;
	}
}
